#include<vector>
#include<queue>
using namespace std;

struct TreeNode {
      int val;
      TreeNode *left;
      TreeNode *right;
      TreeNode(int x) : val(x), left(NULL), right(NULL) {}
  };
class Solution {
public:
    vector<int> levelOrder(TreeNode* root) {
        if (root == NULL)
            return vector<int>();
        
        vector<int> res;
        queue<TreeNode*> q;
        q.push(root);
        
        while (!q.empty())
        {
            int sie = q.size();
            for(int i=0; i<sie; i++){
                TreeNode* cur = q.front();
                q.pop();
                res.push_back(cur->val);
                if (cur->left) q.push(cur->left);
                if(cur->right)q.push(cur->right);
            }
        }
        return res;

    }
};